<?php
// +----------------------------------------------------------------------
// | 有小象汇 自研正版源码 赋能开发者
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 http://www.uxphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 有小象汇并不是自由软件，未经许可不能去掉有小象汇相关版权
// +----------------------------------------------------------------------
// | Author:  有小象汇
// +----------------------------------------------------------------------

namespace app\dao\car;


use app\dao\BaseDao;
use app\model\car\BaseCityFee;

/**
 * Class BaseCityFeeDao
 * @package app\dao\shendeng
 */
class BaseCityFeeDao extends BaseDao
{
    protected function setModel(): string
    {
        return BaseCityFee::class;
    }

    /**
     * 列表
     * @param array $where
     * @param int $page
     * @param int $limit
     * @return array
     */
    public function getList(array $where, int $page,int $limit){
        $model = $this->getModel()->alias('f')->where('f.is_del','=',0);
        $model = $model->field('f.*,c1.city_name as start_city_name,c2.city_name as end_city_name');
        $model = $model->join('base_city c1','f.start_city_id=c1.id','left')->join('base_city c2','f.end_city_id=c2.id','left');
        $model = $this->setSearch($model,$where);
        $count = $model->count();
        $list = $model->order('f.id desc')->page($page, $limit)->select()->toArray();
        return compact('list','count');
    }

    /**
     * 搜索条件
     * @param $model
     * @param $where
     * @return mixed
     */
    public function setSearch($model,$where){
        if(isset($where['start_city_id'])&&$where['start_city_id']){
            $model->where('f.start_city_id','=',$where['start_city_id']);
        }
        if(isset($where['end_city_id'])&&$where['end_city_id']){
            $model->where('f.end_city_id','=',$where['end_city_id']);
        }
        if(isset($where['city_fee'])&&$where['city_fee']){
            $model->where('f.city_fee','=',$where['city_fee']);
        }
        return $model;
    }
}
